package com.example.Controller;

import com.example.entity.Board;
import com.example.service.BoardService;
import com.example.utils.ResultData;
import com.example.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * The type Board controller.
 * @author XingGao
 */
@CrossOrigin //跨域
@RestController
@RequestMapping(value = "/api")
public class BoardController {
    @Autowired
    private BoardService boardService;

    /**
     * Gets board.
     *
     * @return the board
     */
    @PostMapping(value = "getboard")
    public ResultData getBoard() {

        return boardService.getBoard();
    }

    /**
     * Add board result data.
     *
     * @param board the board
     * @return the result data
     */
    @PostMapping(value = "addboard")
    @ResponseBody
    public ResultData addBoard(@RequestBody Board board) {
        if (!board.getMessage().equals("")) {
            return boardService.addBoard(board);
        } else {
            return ResultUtils.error("留言不能为空，请重新输入！", null);
        }

    }


}

